package com.gary.jvmStack;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

/**
 * @author peng_rui
 * @date 2022/8/8
 * 模拟短信发送超时，但此时仍有大量任务进入队列
 *  原因 Executors.newFixedThreadPool(n) 方法的实现中，使用了无边界的阻塞队列LinkedBlockingQueue，大量任务进入队列
 *      无法被处理导致内存一处
 *  -Xmx64m
 */
public class ThreadOverFlowTest {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(2);
        Executors.newCachedThreadPool();
        System.out.println("begin...");
        while (true) {
            service.submit(() -> {
                try {
                    System.out.println("send sms...");
                    TimeUnit.SECONDS.sleep(30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
